package com.chukun.netty.zerocopy;

import java.io.FileInputStream;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.channels.FileChannel;
import java.nio.channels.SocketChannel;

/**
 * @author chukun
 * new io客户端代码
 */
public class NewIOClient {

    public static void main(String[] args) throws IOException {
        SocketChannel socketChannel = SocketChannel.open();
        socketChannel.socket().connect(new InetSocketAddress(8899));
        socketChannel.configureBlocking(true);
        FileChannel fileChannel = new FileInputStream("G:\\linux-bigdata\\apache\\hadoop\\hadoop-2.7.2.tar.gz").getChannel();

        long start = System.currentTimeMillis();
        long transferCount = fileChannel.transferTo(0, fileChannel.size(), socketChannel);
        System.out.println("发送字节数: "+transferCount+", 耗时: "+(System.currentTimeMillis()-start));
        fileChannel.close();
    }
}
